composer-sample-networks

1. 创建business network

clone官方示例,获取Business Network Definitions

git clone https://github.com/hyperledger/composer-sample-networks.git

clone

2. 安装 Lerna 来 build 该仓库文件

$ npm install -g lerna

lerna1

3. bootstrap the repository

安装依赖,链接package(正如normal node.js package)

$ lerna bootstrap

lerna2

lerna3

4. 使用lerna一次性在所有packege中执行npm命令

$ lerna run test

lerna5

bond1

自动生成打包好的.bna文件

bond2

5. Bond Network

Bond债券 Network

The Bond Network allows the issuer of a bond to update the bond information whilst other members of the business network can only read the bond data.

  • Participants Issuer Member
  • Assets BondAsset
  • Transactions PublishBond

The PublishBond transaction submitted by an Issuer participant will create a new BondAsset.

  • Create a Issuer participant:
1
2
3
4
5
{
"$class": "org.acme.bond.Issuer",
"memberId": "memberId:1",
"name": "Billy Thompson"
}
  • Create a Member participant:
1
2
3
4
5
{
"$class": "org.acme.bond.Member",
"memberId": "memberId:1",
"name": "Jenny Jones"
}
  • Submit a PublishBond transaction:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
"$class": "org.acme.bond.PublishBond",
"ISINCode": "ISINCode:1234",
"bond": {
"$class": "org.acme.bond.Bond",
"instrumentId": [],
"exchangeId": [],
"maturity": "2017-07-13T09:39:05.369Z",
"parValue": 1000,
"faceAmount": 1000,
"paymentFrequency": {
"$class": "org.acme.bond.PaymentFrequency",
"periodMultiplier": 0,
"period": "DAY"
},
"dayCountFraction": "",
"issuer": "resource:org.acme.bond.Issuer#memberId:1"
}
}
  • bond.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
describe('#publish', () => {

it('should be able to publish a bond', () => {

const factory = businessNetworkConnection.getBusinessNetwork().getFactory();

// create the issuer发行人
const issuer = factory.newResource(namespace, 'Issuer', 'daniel.selman@example.com');
issuer.name = 'Dan Selman Holdings';

// create the bond
const paymentFrequency = factory.newConcept(namespace, 'PaymentFrequency');
paymentFrequency.periodMultiplier = 6;
paymentFrequency.period = 'MONTH';
const bond = factory.newConcept(namespace, 'Bond');
bond.instrumentId = ['ACME'];
bond.exchangeId = ['NYSE'];
bond.maturity = new Date('2018-02-27T21:03:52+00:00');
bond.parValue = 1000;
bond.faceAmount = 1000;
bond.paymentFrequency = paymentFrequency;
bond.dayCountFraction = 'EOM';
bond.issuer = factory.newRelationship(namespace, 'Issuer', issuer.$identifier);

// create the publish the bond transaction
const publishBond = factory.newTransaction(namespace, 'PublishBond');
publishBond.bond = bond;
publishBond.ISINCode = 'US4592001014';

return businessNetworkConnection.getParticipantRegistry(namespace + '.Issuer')
.then((issuerRegistry) => {
// add the issuers
return issuerRegistry.addAll([issuer]);
})
.then(() => {
// submit the publishBond
return businessNetworkConnection.submitTransaction(publishBond);
})
.then(() => {
return businessNetworkConnection.getAssetRegistry(namespace + '.BondAsset');
})
.then((bondRegistry) => {
// get the bond and check its contents
return bondRegistry.get(publishBond.ISINCode);
})
.then((newBondAsset) => {
newBondAsset.ISINCode.should.equal(publishBond.ISINCode);
});
});
});